package equipments;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import systems.database.DataBaseHandler;
import systems.languages.MultiLanguages;
import tools.Visitable;
import tools.Visitor;

public class DivineStone implements Items,Visitable {

  private int id = 0;
  private String name;
  private int level;
  private String description;

  public DivineStone(){}

  @Override
  public void init(String id) {
    this.id = Integer.valueOf(id);
    this.initItem(DataBaseHandler.getStatement());
  }

  @Override
  public int getLevel() {
    return this.level;
  }

  @Override
  public String getName() {
    return this.name;
  }

  @Override
  public int getNbBonusAttr() {
    return 0;
  }

  @Override
  public int getNbManastone() {
    return 0;
  }

  @Override
  public boolean hasDivineSlot() {
    return false;
  }

  @Override
  public void initItem(Statement transmission) {
    ResultSet resultat;
    String descName="";
    try {

      //Recuperation de l'id de l'arme
      resultat= transmission.executeQuery("Select oid from strings_fr where body like '"+this.name+"' and oid > 100000000");
      while(resultat.next())
        this.id=resultat.getInt("oid");
      //Recuperation des stats des initialisation
      resultat = transmission.executeQuery("Select * from items where id="+id);
      while(resultat.next())
      {
        this.level = resultat.getInt("level");
        descName = resultat.getString("desc_long");
      }
      resultat = transmission.executeQuery("Select body from strings_fr where name like '"+descName+"'");
      while(resultat.next())
      {
        this.description = resultat.getString("body");
      }


    } catch (SQLException e) {
      e.printStackTrace();
    }
    //	System.out.println(this.toString());
  }

  public String toString()
  {
    return "Name :"+ this.name+
    "\nlevel: "+this.level+
    "\ndescription : "+this.description;
  }

  @Override
  public void accept(Visitor visitor) {
    visitor.visit(this);
  }

  @Override
  public int getID() {
    return this.id;
  }

  @Override
  public void updateName() {
    ResultSet resultat;
    try {
      resultat= DataBaseHandler.getStatement().executeQuery("SELECT body FROM "
          +MultiLanguages.getProperties("database.Language.name")
          +" where oid = "+this.id);
      while(resultat.next())
        this.name=resultat.getString("body");  
    } catch (SQLException e) {
      e.printStackTrace();
    }   
  }

  @Override
  public void acceptBonusRemoval(Visitor visitor) {
    visitor.bonusvisit(this);		
  }

}
